/*
 * @Author: czy
 * @Date: 2021-04-29 08:00:28
 * @LastEditTime: 2021-05-21 22:46:49
 */
#include "exception.h"

#define JUMP_BUFFER_SIZE 200
static jmp_buf Jump_Buffers[JUMP_BUFFER_SIZE];
static int jump_flags[JUMP_BUFFER_SIZE]; 
static int jump_buffer_index = -1;

/**
 * @description: Add jump_buffer index.
 * @param i     1 for increase, -1 for decrease.
 */
void add_jump_buffer_index(int i)
{
    if (i > 0)
    {
        jump_buffer_index++;
    } else if (i < 0)
    {
        jump_buffer_index--;
    }
}

/**
 * @description: Get jump_buffer index.
 * @return Jump_buffer index.
 */
int get_jump_buffer_index(void)
{
    return jump_buffer_index;
}

/**
 * @description: Get jump_buffer flag.
 * @param index Index.
 * @return Flag.
 */
int get_jump_flags(int index)
{
    return jump_flags[index];
}

/**
 * @description: Set jump_buffer flag.
 * @param index Index.
 * @param value Value.
 */
void set_jump_flags(int index, int value)
{
    jump_flags[index] = value;
}

/**
 * @description: Get jump_buffer.
 * @return Jump_buffer.
 */
jmp_buf *get_jump_buffer(void)
{
    return &Jump_Buffers[jump_buffer_index];
}
